from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-27 14:02:48.898654
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 27, Aug, 2022
Time: 14:02:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2258
Nobs: 761.000 HQIC: -50.5628
Log likelihood: 9691.15 FPE: 8.89600e-23
AIC: -50.7739 Det(Omega_mle): 7.90983e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300112 0.054876 5.469 0.000
L1.Burgenland 0.106816 0.036494 2.927 0.003
L1.Kärnten -0.106651 0.019379 -5.503 0.000
L1.Niederösterreich 0.206360 0.076231 2.707 0.007
L1.Oberösterreich 0.112065 0.073956 1.515 0.130
L1.Salzburg 0.252854 0.039033 6.478 0.000
L1.Steiermark 0.036773 0.050929 0.722 0.470
L1.Tirol 0.107136 0.041218 2.599 0.009
L1.Vorarlberg -0.060526 0.035441 -1.708 0.088
L1.Wien 0.049870 0.065745 0.759 0.448
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060946 0.114043 0.534 0.593
L1.Burgenland -0.034912 0.075842 -0.460 0.645
L1.Kärnten 0.047365 0.040274 1.176 0.240
L1.Niederösterreich -0.173783 0.158422 -1.097 0.273
L1.Oberösterreich 0.396596 0.153695 2.580 0.010
L1.Salzburg 0.289779 0.081119 3.572 0.000
L1.Steiermark 0.105021 0.105840 0.992 0.321
L1.Tirol 0.314137 0.085659 3.667 0.000
L1.Vorarlberg 0.026819 0.073654 0.364 0.716
L1.Wien -0.024607 0.136631 -0.180 0.857
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190996 0.028217 6.769 0.000
L1.Burgenland 0.089381 0.018765 4.763 0.000
L1.Kärnten -0.008730 0.009965 -0.876 0.381
L1.Niederösterreich 0.259527 0.039197 6.621 0.000
L1.Oberösterreich 0.135056 0.038028 3.552 0.000
L1.Salzburg 0.045752 0.020071 2.280 0.023
L1.Steiermark 0.017362 0.026187 0.663 0.507
L1.Tirol 0.093642 0.021194 4.418 0.000
L1.Vorarlberg 0.058291 0.018223 3.199 0.001
L1.Wien 0.119825 0.033805 3.545 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107843 0.028662 3.763 0.000
L1.Burgenland 0.047180 0.019061 2.475 0.013
L1.Kärnten -0.014736 0.010122 -1.456 0.145
L1.Niederösterreich 0.192268 0.039816 4.829 0.000
L1.Oberösterreich 0.290366 0.038628 7.517 0.000
L1.Salzburg 0.111784 0.020387 5.483 0.000
L1.Steiermark 0.101948 0.026600 3.833 0.000
L1.Tirol 0.110356 0.021528 5.126 0.000
L1.Vorarlberg 0.069511 0.018511 3.755 0.000
L1.Wien -0.017255 0.034339 -0.502 0.615
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130547 0.052049 2.508 0.012
L1.Burgenland -0.051954 0.034614 -1.501 0.133
L1.Kärnten -0.040261 0.018381 -2.190 0.028
L1.Niederösterreich 0.170176 0.072303 2.354 0.019
L1.Oberösterreich 0.141243 0.070146 2.014 0.044
L1.Salzburg 0.288014 0.037022 7.779 0.000
L1.Steiermark 0.032009 0.048305 0.663 0.508
L1.Tirol 0.161679 0.039094 4.136 0.000
L1.Vorarlberg 0.100850 0.033615 3.000 0.003
L1.Wien 0.069669 0.062358 1.117 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056274 0.041463 1.357 0.175
L1.Burgenland 0.040331 0.027574 1.463 0.144
L1.Kärnten 0.050248 0.014643 3.432 0.001
L1.Niederösterreich 0.220856 0.057598 3.834 0.000
L1.Oberösterreich 0.283967 0.055879 5.082 0.000
L1.Salzburg 0.045778 0.029493 1.552 0.121
L1.Steiermark -0.001417 0.038481 -0.037 0.971
L1.Tirol 0.148086 0.031143 4.755 0.000
L1.Vorarlberg 0.072459 0.026778 2.706 0.007
L1.Wien 0.084251 0.049675 1.696 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180373 0.049656 3.632 0.000
L1.Burgenland -0.005671 0.033022 -0.172 0.864
L1.Kärnten -0.061374 0.017536 -3.500 0.000
L1.Niederösterreich -0.082633 0.068979 -1.198 0.231
L1.Oberösterreich 0.197245 0.066921 2.947 0.003
L1.Salzburg 0.056223 0.035320 1.592 0.111
L1.Steiermark 0.230618 0.046084 5.004 0.000
L1.Tirol 0.493843 0.037297 13.241 0.000
L1.Vorarlberg 0.047573 0.032070 1.483 0.138
L1.Wien -0.053976 0.059491 -0.907 0.364
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166017 0.057017 2.912 0.004
L1.Burgenland -0.011055 0.037918 -0.292 0.771
L1.Kärnten 0.067106 0.020136 3.333 0.001
L1.Niederösterreich 0.206376 0.079205 2.606 0.009
L1.Oberösterreich -0.070331 0.076842 -0.915 0.360
L1.Salzburg 0.211324 0.040556 5.211 0.000
L1.Steiermark 0.115614 0.052916 2.185 0.029
L1.Tirol 0.071713 0.042826 1.674 0.094
L1.Vorarlberg 0.121666 0.036824 3.304 0.001
L1.Wien 0.123168 0.068310 1.803 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360550 0.032888 10.963 0.000
L1.Burgenland 0.006139 0.021872 0.281 0.779
L1.Kärnten -0.023420 0.011614 -2.016 0.044
L1.Niederösterreich 0.214796 0.045687 4.702 0.000
L1.Oberösterreich 0.192291 0.044323 4.338 0.000
L1.Salzburg 0.045597 0.023394 1.949 0.051
L1.Steiermark -0.017556 0.030523 -0.575 0.565
L1.Tirol 0.106008 0.024703 4.291 0.000
L1.Vorarlberg 0.073049 0.021241 3.439 0.001
L1.Wien 0.044224 0.039402 1.122 0.262
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040254 0.148723 0.192537 0.157825 0.124227 0.112847 0.066127 0.222965
Kärnten 0.040254 1.000000 -0.004272 0.133200 0.040911 0.095874 0.431024 -0.052339 0.100160
Niederösterreich 0.148723 -0.004272 1.000000 0.337269 0.149596 0.298895 0.107261 0.182935 0.322565
Oberösterreich 0.192537 0.133200 0.337269 1.000000 0.227767 0.330954 0.172528 0.167873 0.264944
Salzburg 0.157825 0.040911 0.149596 0.227767 1.000000 0.147170 0.122429 0.147527 0.131699
Steiermark 0.124227 0.095874 0.298895 0.330954 0.147170 1.000000 0.150880 0.138135 0.078928
Tirol 0.112847 0.431024 0.107261 0.172528 0.122429 0.150880 1.000000 0.115018 0.151965
Vorarlberg 0.066127 -0.052339 0.182935 0.167873 0.147527 0.138135 0.115018 1.000000 0.006674
Wien 0.222965 0.100160 0.322565 0.264944 0.131699 0.078928 0.151965 0.006674 1.000000